<%@ page import="yc.day0109.lottery.dao.UserDao" %>
<%@ page import="yc.day0109.lottery.dao.impl.UserDaoImpl" %>
<%@ page import="yc.day0109.lottery.po.User" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="yc.day0109.lottery.service.UserMgr" %><%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2023/1/9
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>保存用户信息</title>
    <%
        //获取addUser.jsp页面中，用户名和手机号
        String userName = request.getParameter("userName");
        String phone = request.getParameter("phone");
        //多态体现，创建UserDao数据访问层
        UserDao userDao = new UserDaoImpl();
        //创建User对象,用来保存添加用户信息
        User user = new User();
        //用户名
        user.setUserName(userName);
        //手机号
        user.setPhone(phone);
        //中签编码(根据要求随机生成，调用随机生成方法)
        String markNo = UserMgr.getCharRandomNum(10);
        user.setMarkNo(markNo);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        //开户日期(当前系统时间)
        user.setOpenDate(sf.format(new Date()));
        int addRes = userDao.addUser(user);
        if(addRes > 0){
            //跳转到index.jsp页面
            //转发和重定向
            request.getRequestDispatcher("index.jsp").forward(request,response);
        }else {
            out.print("添加失败!");
        }
    %>
</head>
<body>

</body>
</html>
